import { createRouter, createWebHistory } from 'vue-router'
import LoginView from '../views/LoginView.vue'
import CustomerHome from '../views/Customer/CustomerHome.vue'
import EmployeeDashboard from '../views/Employee/EmployeeDashboard.vue'
import AdminManage from '../views/admin/AdminManage.vue'
import RegisterView from '../views/admin/RegisterView.vue'
import AddCustomerView from '../views/admin/AddCustomerView.vue'
import ChangePassword from '../views/admin/ChangePassword.vue'
import ContractCreate from '../views/Employee/PROJECT_MANAGER/ContractCreate.vue'
import ContractEdit from '../views/Employee/PROJECT_MANAGER/ContractEdit.vue'
import ContractDetail from '../views/General/ContractDetail.vue'
import ChangePasswordEmployee from '../views/Employee/ChangePasswordEmployee.vue'
import ChangePasswordCustomer from "@/views/Customer/ChangePasswordCustomer";
import ClauseSelectPage from '../views/Employee/PROJECT_MANAGER/ClauseSelectPage.vue'
import ClauseCreate from '../views/Employee/PROJECT_MANAGER/ClauseCreate.vue'
import SubmitReview from '../views/Employee/PROJECT_MANAGER/SubmitReview.vue'
import AuditContracts from '../views/Employee/SPECIALIST/AuditContracts.vue'
import AuditContractDetail from '../views/Employee/SPECIALIST/AuditContractDetail.vue'
import AuditClause from '../views/Employee/SPECIALIST/AuditClause.vue'
import CustomerAuditContracts from "@/views/Customer/CustomerAuditContracts";
import CustomerAuditContractDetail from "@/views/Customer/CustomerAuditContractDetail";
import CustomerAuditClause from "@/views/Customer/CustomerAuditClause";
import ClauseDetail from '../views/Employee/PROJECT_MANAGER/ClauseDetail.vue'
import ContractDetail2 from '../views/General/ContractDetail2.vue'
import CustomerContracts from '../views/Customer/CustomerContracts.vue'
import EmployeeContracts from '../views/Employee/EmployeeContracts.vue'
// 新增：签订合同相关视图
import EmployeePendingSignContracts from '../views/Employee/PROJECT_MANAGER/EmployeePendingSignContracts.vue'
import ContractSignConfirm from '../views/General/ContractSignConfirm.vue'
import CustomerConfirmContracts from "@/views/Customer/CustomerConfirmContracts";
import CustomerConfirmContractDetail from "@/views/Customer/CustomerConfirmContractDetail";
import ContractProgressDetail from "@/views/ContractProgressDetail";
import EmployeeOngoingContracts from "@/views/Employee/PROJECT_MANAGER/EmployeeOngoingContracts";
import CustomerOngoingContracts from "@/views/Customer/CustomerOngoingContracts";
import CustomerContractProgressDetail from "@/views/Customer/CustomerContractProgressDetail";
import CustomerArchivedContracts from "@/views/Customer/CustomerArchivedContracts";
import ArchivedContractDetail from "@/views/General/ArchivedContractDetail";
import EmployeeArchivedContractDetail2 from "@/views/Employee/EmployeeArchivedContractDetail2";
import EmployeeArchivedContracts from "@/views/Employee/EmployeeArchivedContracts";
import PayPage from "@/views/Customer/PayPage";

const routes = [
    {
        path: '/',
        redirect: '/login'
    },
    {
        path: '/login',
        name: 'Login',
        component: LoginView
    },
    {
        path: '/customer/home',
        name: 'CustomerHome',
        component: CustomerHome
    },
    {
        path: '/employee/dashboard',
        name: 'EmployeeDashboard',
        component: EmployeeDashboard,
        meta: { requiresRole: 'employee' }
    },
    {
        path: '/employee/change-password',
        name: 'ChangePasswordEmployee',
        component: ChangePasswordEmployee,
        meta: { requiresRole: 'employee' }
    },
    {
        path: '/admin/manage',
        name: 'AdminManage',
        component: AdminManage,
        meta: { requiresRole: 'admin' }
    },
    {
        path: '/register',
        name: 'Register',
        component: RegisterView
    },
    {
        path: '/admin/customer/add',
        name: 'AddCustomer',
        component: AddCustomerView,
        meta: { requiresRole: 'admin' }
    },
    {
        path: '/admin/change-password',
        name: 'ChangePassword',
        component: ChangePassword,
        meta: { requiresRole: 'admin' }
    },
    {
        path: '/customer/change-password',
        name: 'ChangePasswordCustomer',
        component: ChangePasswordCustomer
    },
    {
        path: '/contract/create',
        name: 'ContractCreate',
        component: ContractCreate,
        meta: { requiresRole: 'employee' }
    },
    {
        path: '/contracts/:contractId/edit',
        name: 'ContractEdit',
        component: ContractEdit,
        meta: { requiresRole: 'employee' }
    },
    {
        path: '/contracts/:contractId',
        name: 'ContractDetail',
        component: ContractDetail,
        meta: { requiresRole: 'employee' }
    },
    {
        path: '/contracts/:contractId/clauses/select',
        name: 'ClauseSelect',
        component: ClauseSelectPage,
        meta: { requiresRole: 'employee' }
    },
    {
        path: '/contracts/:contractId/clauses/new',
        name: 'ClauseCreate',
        component: ClauseCreate,
        meta: { requiresRole: 'employee' }
    },
    {
        path: '/employee/submit-review',
        name: 'SubmitReview',
        component: SubmitReview,
        meta: { requiresRole: 'employee', requiresPosition: 'PROJECT_MANAGER' }
    },
    {
        path: '/employee/audit-contracts',
        name: 'AuditContracts',
        component: AuditContracts,
        meta: { requiresRole: 'employee', requiresPosition: ['LEGAL_SPECIALIST', 'FINANCE_SPECIALIST'] }
    },
    {
        path: '/employee/audit-contract/:contractId',
        name: 'AuditContractDetail',
        component: AuditContractDetail,
        meta: { requiresRole: 'employee', requiresPosition: ['LEGAL_SPECIALIST', 'FINANCE_SPECIALIST'] }
    },
    {
        path: '/employee/audit-clause/:contractId/:clauseId',
        name: 'AuditClause',
        component: AuditClause,
        meta: { requiresRole: 'employee', requiresPosition: ['LEGAL_SPECIALIST', 'FINANCE_SPECIALIST'] }
    },
    {
        path: '/customer/audit-contracts',
        name: 'CustomerAuditContracts',
        component: CustomerAuditContracts
    },
    {
        path: '/customer/audit-contract/:contractId',
        name: 'CustomerAuditContractDetail',
        component: CustomerAuditContractDetail
    },
    {
        path: '/customer/audit-clause/:contractId/:clauseId',
        name: 'CustomerAuditClause',
        component: CustomerAuditClause
    },
    {
        path: '/contracts/:contractId/clauses/:clauseId/detail',
        name: 'ClauseDetail',
        component: ClauseDetail,
        meta: { requiresRole: 'employee' }
    },
    {
        path: '/customer/contracts',
        name: 'CustomerContracts',
        component: CustomerContracts
    },
    {
        path: '/contracts/:contractId/detail2',
        name: 'ContractDetail2',
        component: ContractDetail2
    },
    {
        path: '/employee/my-contracts',
        name: 'EmployeeContracts',
        component: EmployeeContracts
    },
    // 新增：待签订合同列表路由
    {
        path: '/employee/pending-sign',
        name: 'EmployeePendingSignContracts',
        component: EmployeePendingSignContracts,
        meta: { requiresRole: 'employee', requiresPosition: 'PROJECT_MANAGER' }
    },
    // 新增：确认签订合同路由
    {
        path: '/contracts/:contractId/sign',
        name: 'ContractSignConfirm',
        component: ContractSignConfirm,
        meta: { requiresRole: 'employee', requiresPosition: 'PROJECT_MANAGER' }
    },
    {
        path: '/customer/confirm-contracts',
        name: 'CustomerConfirmContracts',
        component: CustomerConfirmContracts
    },
    {
        path: '/customer/contracts/:contractId/confirm',
        name: 'CustomerConfirmContractDetail',
        component: CustomerConfirmContractDetail
    },
    {
        path: '/employee/ongoing-contracts',
        name: 'EmployeeOngoingContracts',
        component: EmployeeOngoingContracts,
        meta: { requiresRole: 'employee', requiresPosition: 'PROJECT_MANAGER' }
    },
    {
        path: '/employee/contracts/:contractId/progress',
        name: 'ContractProgressDetail',
        component: ContractProgressDetail,
        meta: { requiresRole: 'employee', requiresPosition: 'PROJECT_MANAGER' }
    },
    {
        path: '/customer/ongoing-contracts',
        name: 'CustomerOngoingContracts',
        component: CustomerOngoingContracts
    },
    {
        path: '/customer/contracts/:contractId/progress',
        name: 'CustomerContractProgressDetail',
        component: CustomerContractProgressDetail,
        // props: true
    },
    {
        path: '/customer/archived-contracts',
        name: 'CustomerArchivedContracts',
        component: CustomerArchivedContracts
    },
    {
        path: '/customer/contracts/:contractId/archived-detail',
        name: 'ArchivedContractDetail',
        component: ArchivedContractDetail,
        // props: true
    },
    {
        path: '/employee/archived-contracts',
        name: 'EmployeeArchivedContracts',
        component: EmployeeArchivedContracts
    },
    {
        path: '/employee/contracts/:contractId/archived-detail',
        name: 'EmployeeArchivedContractDetail2',
        component: EmployeeArchivedContractDetail2,
        // props: true
    },
    {
        path: '/customer/pay',  // 新支付页面路由
        name: 'PayPage',
        component: PayPage
    }
]

const router = createRouter({
    history: createWebHistory(),
    routes
})
export default router